package Controller.CreditCardController;

import Utils.BaseMessage;
import Utils.isString;
import ViewOption.creditCardVo;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "AddCreditCardServlet", urlPatterns = {
        "/api/CreditCard/isLogin/AddCreditCardServlet"
})
public class AddCreditCardServlet extends HttpServlet {
    private final creditCardVo creditCardVo = new creditCardVo();
    private final isString isString = new isString();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String cardNumId = request.getParameter("cardNumId");
        String cardPrice = request.getParameter("cardPrice");
        String cardTime = request.getParameter("cardTime");
        String bankId = request.getParameter("bankId");
        if (isString.IsEmpty(cardNumId, cardPrice, cardTime, bankId)) {
            response.getWriter().print(JSON.toJSONString(new BaseMessage(2, "非法传参", null)));
            return;
        }
        response.getWriter().print(JSON.toJSONString(creditCardVo.insertCreditCardByUserId(request)));
        return;
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
